package com.redis.config;

import com.rabbitmq.client.Channel;

import com.redis.constant.OrderMQConstants;
import com.redis.enty.OrderInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
public class DeadLetterQueueConsumer {
//    /**
//     * 监听取消订单
//     * @param message
//     * @param channel
//     * @throws Exception
//     */
//    @RabbitListener(queues = OrderMQConstants.CANCEL_ORDER_DEAD_QUEUE)
//    public void cancelOrderDead(OrderInfo orderInfo,Message message, Channel channel) throws Exception{
//        String msg = new String(message.getBody());
//        log.info("当前时间：{}，取消订单发送一条消息给两个TTL队列：{}",new Date().toString(),orderInfo.toString());
//
//    }
//
//    /**
//     * 监听订单自动收货
//     * @param message
//     * @param channel
//     * @throws Exception
//     */
//    @RabbitListener(queues = OrderMQConstants.RECEIVED_ORDER_DEAD_QUEUE)
//    public void receivedOrderDead(OrderInfo orderInfo,Message message, Channel channel) throws Exception{
//        String msg = new String(message.getBody());
//        log.info("当前时间：{}，自动收货发送一条消息给两个TTL队列：{}",new Date().toString(),orderInfo.toString());
//
//
//    }

    @RabbitListener(queues = OrderMQConstants.CANCEL_ORDER_QUEUE)
    public void receiveCancelMsg(Message messages){
        String msg = new String(messages.getBody());
        log.info("当前时间：{},自动取消订单信息：{}",new Date().toString(),msg);
    }

    @RabbitListener(queues = OrderMQConstants.RECEIVED_ORDER_QUEUE)
    public void receiveReceivedMsg(Message messages){
        String msg = new String(messages.getBody());
        log.info("当前时间：{},自动收货信息：{}",new Date().toString(),msg);
    }

}
